package me.ingxin.android.permission2.ext

import android.Manifest
import android.content.Context
import android.util.Log
import me.ingxin.android.permission2.PERMISSION_ACCESS_BACKGROUND_LOCATION
import me.ingxin.android.permission2.permissionGranted

/**
 * Created on 2023/7/16 by yin
 */
internal class BackgroundLocationPermissionTask : PlusNormalPermissionTask() {

    override val permission = PERMISSION_ACCESS_BACKGROUND_LOCATION

    override fun hasBasePermission(context: Context): Boolean {
        val accessFindLocationGranted =
            context.permissionGranted(Manifest.permission.ACCESS_FINE_LOCATION)
        val accessCoarseLocationGranted =
            context.permissionGranted(Manifest.permission.ACCESS_COARSE_LOCATION)
        if (!accessFindLocationGranted && !accessCoarseLocationGranted) {
            //没有获取到基础权限，直接失败
            Log.e(
                "BackgroundLocationPermissionTask",
                "location permission not granted, can not request ACCESS_BACKGROUND_LOCATION"
            )
            return false
        }
        return true
    }

}